package project.newCode.gui;

import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.JSplitPane;
import javax.swing.JSlider;
import javax.swing.SwingConstants;
import javax.swing.JTextPane;
import javax.swing.border.EtchedBorder;

import project.hulpPakket.Color3f;
import project.newCode.lights.Light;

import java.awt.Color;
import java.awt.Dimension;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import project.newCode.*;

public class LightSubPanel extends JPanel {

	private Light light;
	private JSlider intensity;
	private JSlider sliderR;
	private JSlider sliderB;
	private JSlider sliderG;
	private JPanel panel;
	private JPanel panel_1;
	private JTextPane txtpnR;
	private JTextPane txtpnG;
	private JTextPane txtpnB;
	private testRenderer t;
	public LightSubPanel(String name, Light light, testRenderer t) {
		this();
		this.t = t;
		this.light = light;
		setBorder(new TitledBorder(null, name, TitledBorder.LEADING, TitledBorder.TOP, null, null));
		intensity.setValue((int) Math.round(light.getIntensity()*100));
		sliderR.setValue((int) Math.round(light.getColor().x*100));
		sliderG.setValue((int) Math.round(light.getColor().y*100));
		sliderB.setValue((int) Math.round(light.getColor().z*100));
		this.setPreferredSize(new Dimension(210, 250));
	}
	/**
	 * Create the panel.
	 */
	public LightSubPanel() {
		setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Border", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		setLayout(null);
		
		panel = new JPanel();
		panel.setBorder(new TitledBorder(null, "Intensity", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel.setBounds(6, 26, 63, 215);
		add(panel);
		
		intensity = new JSlider();
		intensity.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent arg0) {
				JSlider s = (JSlider) arg0.getSource();
				light.setIntensity(s.getValue()/100F);
				t.repaint();
			}
		});
		intensity.setOrientation(SwingConstants.VERTICAL);
		panel.add(intensity);
		
		panel_1 = new JPanel();
		panel_1.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Color", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		panel_1.setBounds(81, 26, 123, 215);
		add(panel_1);
		panel_1.setLayout(null);
		
		txtpnR = new JTextPane();
		txtpnR.setBounds(6, 17, 29, 23);
		txtpnR.setText("R");
		panel_1.add(txtpnR);
		
		sliderG = new JSlider();
		sliderG.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e) {
				JSlider s = (JSlider) e.getSource();
				light.setColor(new Color3f(light.getColor().x,s.getValue()/100F,light.getColor().z));
				t.repaint();
			}
		});
		sliderG.setBounds(44, 27, 29, 190);
		sliderG.setOrientation(SwingConstants.VERTICAL);
		panel_1.add(sliderG);
		
		sliderB = new JSlider();
		sliderB.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e) {
				JSlider s = (JSlider) e.getSource();
				light.setColor(new Color3f(light.getColor().x,light.getColor().y,s.getValue()/100F));
				t.repaint();
			}
		});
		sliderB.setBounds(85, 27, 29, 190);
		sliderB.setOrientation(SwingConstants.VERTICAL);
		panel_1.add(sliderB);
		
		sliderR = new JSlider();
		sliderR.addChangeListener(new ChangeListener() {
			public void stateChanged(ChangeEvent e) {
				JSlider s = (JSlider) e.getSource();
				light.setColor(new Color3f(s.getValue()/100F,light.getColor().y,light.getColor().z));
				t.repaint();
			}
		});
		sliderR.setBounds(6, 27, 29, 190);
		sliderR.setOrientation(SwingConstants.VERTICAL);
		panel_1.add(sliderR);
		
		txtpnG = new JTextPane();
		txtpnG.setText("G");
		txtpnG.setBounds(44, 17, 29, 23);
		panel_1.add(txtpnG);
		
		txtpnB = new JTextPane();
		txtpnB.setText("B");
		txtpnB.setBounds(85, 17, 29, 23);
		panel_1.add(txtpnB);

	}
	public void disableAll() {
		panel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Intensity", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0.5F, 0.5F, 0.5F)));
		panel_1.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Color", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0.5F, 0.5F, 0.5F)));
		sliderR.setEnabled(false);
		sliderG.setEnabled(false);
		sliderB.setEnabled(false);
		intensity.setEnabled(false);
		txtpnB.setEnabled(false);
		txtpnG.setEnabled(false);
		txtpnR.setEnabled(false);
		panel.setEnabled(false);
		panel_1.setEnabled(false);
	}
}
